<%@page import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@page import="com.hhit.collaborative_learning.utils.Utils"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String type=request.getParameter("type");
type=type==null?"blog":type;
String choose=request.getParameter("choose");
choose=choose==null?"0":choose;
String currentPage=request.getParameter("currentPage");
currentPage=currentPage==null?"1":currentPage;
if(currentPage.equals("1")){
	Utils.getBlogRightDaysAge(Calendar.getInstance());
}
String category=Utils.getCookieValue("cl_blogRight", request);
PublicDaoImplMySql dao=new PublicDaoImplMySql();
request.setAttribute("rightPage", dao.getBlogRightPage(category, type, choose, currentPage));
request.setAttribute("type", type);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="Stylesheet" href="<%=basePath%>css/main.css" />
<!--new top-->
<link rel="stylesheet" href="<%=basePath%>css/index.css">
<!--new top-->

<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>js/csdn.js"></script>
<script type="text/javascript" src="<%=basePath%>js/master.js"></script>
<script type="text/javascript">
// 	var statichost = "http://static.blog.csdn.net";
</script>


<script type='text/javascript' src='<%=basePath%>js/feedback.js'></script>
</head>

<body>
	<div id="wrap">

		<div class="head">
			<div style="float:right; margin-top:20px; color:Red;"></div>
		</div>

		<div class="tabs_header">
			<ul id="ul_tab" class="tabs">
				<li><a href="<%=basePath%>learning/bloglist.jsp"><span>文章管理</span></a></li>
				<li><a href="<%=basePath%>learning/manage_comment.jsp"><span>评论管理</span></a></li>
				<li><a href="<%=basePath%>learning/postedit.jsp"><span>发表文章</span></a></li>
				<li><a href="<%=basePath%>learning/draft.jsp"><span>草稿箱</span></a></li>
				<li><a href="<%=basePath%>learning/deleted.jsp"><span>回收站</span></a></li>
				<li><a href="<%=basePath%>learning/myattention.jsp"><span>我的关系</span></a></li>
				<c:if test="${cookie.cl_blogRight.value ne null}">
				<li><a href="<%=basePath %>learning/myright.jsp"><span>我的权限</span></a></li>
				</c:if>
			</ul>
		</div>
		<script type="text/javascript">
			setTab();
		</script>

		<p><font color="red">你拥有对<%=Utils.getRelativeName(category) %>方面的最新博文和专家申请操作的权限，请谨慎操作！</font></p>
		<div class="h_status">
			<a href="myright.jsp">最新博文</a><span class="pipe">|</span><a
				href="myright.jsp?type=apply">专家申请</a>
		</div>
		<p id="choose"></p>
		<script type="text/javascript">
			setSubTab();
			function setSubTab() {
			    var type = csdn.urls[3];
			    if (type && type.indexOf("type=apply")>=0){ $(".h_status a")[1].className = "active";}
			    else{ 
			    	$(".h_status a")[0].className = "active";
			    	if('<%=choose%>' =='0'){
				    	$("#choose").append('<input type="radio" name="type" value="0" checked/>全部&nbsp;&nbsp;<input type="radio" name="type" value="1"/>只看专家');
			    	}else{
			    		$("#choose").append('<input type="radio" name="type" value="0"/>全部&nbsp;&nbsp;<input type="radio" name="type" value="1" checked/>只看专家');
			    	}
			    }
			}
			function setTop(blogId,type){
				if(type=='2'){
					alert("转载文章不能置顶!");
					return;
				}
				$.post("<%=basePath%>ManageBlogServlrt",{action:1,blogId:blogId,hasRight:'yes'},function(data,status){
					alert(data);
				});
			}
			function setPrime(blogId){
				$.post("<%=basePath%>ManageBlogServlrt",{action:8,blogId:blogId},function(data,status){
					alert(data);
				});
			}
			function deleteBlog(blogId){
				if(confirm("删除文章将不可恢复，是否继续？")){
					$.post("<%=basePath%>ManageBlogServlrt",{action:2,blogId:blogId},function(data,status){
						location.href="<%=basePath%>learning/myright.jsp?currentPage=<%=currentPage%>&type=<%=type%>&category=<%=category%>&choose=<%=choose%>";
					});
				}
			}
			$(document).ready(function() {
				$("input[name='type']").change(function(){
					var choose= $("input[name='type']:checked").val();
						location.href="<%=basePath%>learning/myright.jsp?choose="+choose+"&category=<%=category%>&type=<%=type%>";
				});
			});
		</script>
		<c:choose>
			<c:when test="${requestScope.type ne 'apply' }">
				<table id="lstBox" cellspacing="0">
					<thead>
						<tr>
							<th class="tdleft" style="width:200px;">标题</th>
							<th style="width:140px;">作者</th>
							<th style="width:140px;">时间</th>
							<th style="width:100px;">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${requestScope.rightPage.list}" var="comment">
							<tr class='altitem'>
								<td class='tdleft'><a
									href='<%=basePath%>learning/article.jsp?blogId=${comment.blogId}&blogName=${comment.blogName}&userId=${comment.userId}'
									target=_blank>${comment.blogName}</a></td>
								<td><a href='<%=basePath%>learning/personal.jsp?userId=${comment.userId}'
									class='user_name' target=_blank>${comment.userName}</a></td>
								<td>${comment.time}</td>
								<td><a class='del' href='#' onclick="setTop('${comment.blogId}','${comment.blogType}');return false;" >置顶</a> | <a class='del' href='#' onclick="setPrime('${comment.blogId}');return false;" >设为精华</a> | <a class='del' href='#' onclick="deleteBlog('${comment.blogId}')" >删除</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</c:when>
			<c:otherwise>
				<table id="lstBox" cellspacing="0">
					<thead>
						<tr>
							<th class="tdleft" style="width:200px;">申请人</th>
<!-- 							<th style="width:140px;">作者</th> -->
							<th style="width:140px;">申请时间</th>
							<th style="width:100px;">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${requestScope.rightPage.list}" var="comment">
							<tr class='altitem'>
								<td class='tdleft'><a
									href='<%=basePath%>learning/personal.jsp?userId=${comment.userId}'
									target=_blank>${comment.userName}</a></td>
<!-- 								<td><a href='<%=basePath%>learning/personal.jsp?userId=${comment.userId}' -->
<!-- 									class='user_name' target=_blank>${comment.userName}</a></td> -->
								<td>${comment.time}</td>
								<td><a class='del' href='<%=basePath %>learning/examineApply.jsp?userId=${comment.userId}' target="_blank">审核</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</c:otherwise>
		</c:choose>
		<c:if test="${requestScope.rightPage.count>0 }">
		<div class="page_nav">
			<span> ${requestScope.rightPage.count }条数据
				共${requestScope.rightPage.totalPage }页</span>
			<c:if test="${requestScope.rightPage.currentPage>1}">
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=1&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">首页</a>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.currentPage-1}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">上一页</a>
			</c:if>
			<c:if test="${requestScope.rightPage.pageDiffer>0}">
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5-4}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">...</a>
			</c:if>

			<c:if
				test="${requestScope.rightPage.pageDiffer*5+1<=requestScope.rightPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.rightPage.currentPage==requestScope.rightPage.pageDiffer*5+1 }">
						<strong>${requestScope.rightPage.pageDiffer*5+1}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+1}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">${requestScope.rightPage.pageDiffer*5+1}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.rightPage.pageDiffer*5+2<=requestScope.rightPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.rightPage.currentPage==requestScope.rightPage.pageDiffer*5+2 }">
						<strong>${requestScope.rightPage.pageDiffer*5+2}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+2}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">${requestScope.rightPage.pageDiffer*5+2}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.rightPage.pageDiffer*5+3<=requestScope.rightPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.rightPage.currentPage==requestScope.rightPage.pageDiffer*5+3 }">
						<strong>${requestScope.rightPage.pageDiffer*5+3}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+3}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">${requestScope.rightPage.pageDiffer*5+3}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.rightPage.pageDiffer*5+4<=requestScope.rightPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.rightPage.currentPage==requestScope.rightPage.pageDiffer*5+4 }">
						<strong>${requestScope.rightPage.pageDiffer*5+4}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+4}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">${requestScope.rightPage.pageDiffer*5+4}</a>
					</c:otherwise>
				</c:choose>
			</c:if>

			<c:if
				test="${requestScope.rightPage.pageDiffer*5+5<=requestScope.rightPage.totalPage}">
				<c:choose>
					<c:when
						test="${requestScope.rightPage.currentPage==requestScope.rightPage.pageDiffer*5+5 }">
						<strong>${requestScope.rightPage.pageDiffer*5+5}</strong>
					</c:when>
					<c:otherwise>
						<a
							href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+5}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">${requestScope.rightPage.pageDiffer*5+5}</a>
					</c:otherwise>
				</c:choose>
			</c:if>
			<c:if
				test="${requestScope.rightPage.totalPage>5 && requestScope.rightPage.pageDiffer<requestScope.rightPage.totalPage/5-1}">
				<a
					href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.pageDiffer*5+6}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">...</a>
			</c:if>
			<c:if
				test="${requestScope.rightPage.currentPage<requestScope.rightPage.totalPage}">
				<a
					href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.currentPage+1}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">下一页</a>
				<a
					href="<%=basePath%>learning/myright.jsp?currentPage=${requestScope.rightPage.totalPage}&type=${requestScope.type}&category=<%=category%>&choose=<%=choose%>">尾页</a>
			</c:if>
		</div>
		</c:if>
	</div>


	<!--     <script type="text/javascript" src="<%=basePath%>js/cnick.js"></script> -->

</body>
</html>